//
//  ProductOrderCell.m
//  MobileShoppingMall
//
//  Created by 冯传昌 on 2021/5/6.
//  Copyright © 2021 冯传昌. All rights reserved.
//

#import "ProductOrderCell.h"

#import "GoodsDetailsViewController.h"

@interface ProductOrderCell()<UIGestureRecognizerDelegate>

@property (nonatomic,strong) UIImageView *goodsImgV;//商品图片

@property (nonatomic,strong) UILabel *goodsInfoLB;//商品介绍lb

@property (nonatomic,strong) UILabel *goodsSkuLB;//商品型号lb

@property (nonatomic,strong) UILabel *goodsPriceLB;//商品价格lb

@property (nonatomic,strong) UILabel *goodsNumberLB;//商品数量lb

@property (nonatomic,strong) UIButton *evaluationBtn;//评价

@property (nonatomic,strong) UIButton *statusBtn;//订单状态

@end

@implementation ProductOrderCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self == [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self initUI];
    }
    return self;
}
#pragma mark - setter
- (void)setModel:(ProductOrderModel *)model{
    _model = model;
    
    [self.goodsImgV sd_setImageWithURL:[NSURL URLWithString:_model.picture]];
    self.goodsInfoLB.text = _model.name;
    self.goodsSkuLB.text = _model.norms;
    self.goodsSkuLB.width = [Configuration getLabelWidthWithText:self.goodsSkuLB.text withFont:self.goodsSkuLB.font];
    self.goodsPriceLB.text = [Configuration getTotalPriceWithPrice:_model.price withTbPrice:_model.tbprice];
    self.goodsPriceLB.width = [Configuration getLabelWidthWithText:self.goodsPriceLB.text withFont:self.goodsPriceLB.font];
    self.goodsNumberLB.text = [NSString stringWithFormat:@"X%ld",(long)_model.number];
    
    if (_model.commentbtn == NO) {
        self.evaluationBtn.hidden = YES;
        [self.statusBtn setTitle:_model.status forState:normal];
        self.statusBtn.right = self.evaluationBtn.right;
    }else{
        self.evaluationBtn.hidden = NO;
        self.statusBtn.right = self.evaluationBtn.left - 3;
    }
}

#pragma mark - UI
-(void)initUI{
    [self.contentView addSubview:self.goodsImgV];
    [self.contentView addSubview:self.goodsInfoLB];
    [self.contentView addSubview:self.goodsSkuLB];
    [self.contentView addSubview:self.goodsPriceLB];
    [self.contentView addSubview:self.goodsNumberLB];
}
#pragma mark - lazy
//商品图片
-(UIImageView *)goodsImgV{
    if (!_goodsImgV) {
        _goodsImgV = [[UIImageView alloc] initWithFrame:CGRectMake(15, 15, 80, 80)];
        _goodsImgV.backgroundColor = MainBackColor;
        _goodsImgV.clipsToBounds = YES;
        _goodsImgV.layer.cornerRadius = 4;
        
        _goodsImgV.userInteractionEnabled = YES;
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapClick:)];
        tap.delegate = self;
        [_goodsImgV addGestureRecognizer:tap];
    }
    return _goodsImgV;
}
//商品信息简介lb
-(UILabel *)goodsInfoLB{
    if (!_goodsInfoLB) {
        _goodsInfoLB = [[UILabel alloc] initWithFrame:CGRectMake(self.goodsImgV.right+10, self.goodsImgV.top, ScreenWidth - 140, 20)];
        _goodsInfoLB.numberOfLines = 1;
        _goodsInfoLB.textAlignment = NSTextAlignmentLeft;
        _goodsInfoLB.textColor = MainBlackTextColor;
        _goodsInfoLB.font = FontSet(14);
    }
    return _goodsInfoLB;
}
//商品信息简介lb
-(UILabel *)goodsSkuLB{
    if (!_goodsSkuLB) {
        _goodsSkuLB = [[UILabel alloc] initWithFrame:CGRectMake(self.goodsImgV.right+10, self.goodsInfoLB.bottom+8, 50, 17)];
        _goodsSkuLB.textAlignment = NSTextAlignmentLeft;
        _goodsSkuLB.backgroundColor = MainBackColor;
        _goodsSkuLB.textColor = MainGrayTextColor;
        _goodsSkuLB.font = FontSet(12);
        _goodsSkuLB.clipsToBounds = YES;
        _goodsSkuLB.layer.cornerRadius = 2;
    }
    return _goodsSkuLB;
}
//商品价格lb
-(UILabel *)goodsPriceLB{
    if (!_goodsPriceLB) {
        _goodsPriceLB = [[UILabel alloc] initWithFrame:CGRectMake(self.goodsImgV.right+10, self.goodsImgV.bottom - 18, 80, 18)];
        _goodsPriceLB.textAlignment = NSTextAlignmentLeft;
        _goodsPriceLB.textColor = RGB(255, 34, 21);
        _goodsPriceLB.font = FontSetWithWeight(13, 0.2f);
    }
    return _goodsPriceLB;
}
//商品数量简介lb
-(UILabel *)goodsNumberLB{
    if (!_goodsNumberLB) {
        _goodsNumberLB = [[UILabel alloc] initWithFrame:CGRectMake(ScreenWidth-75, self.goodsImgV.bottom-20, 35, 20)];
        _goodsNumberLB.textAlignment = NSTextAlignmentRight;
        _goodsNumberLB.textColor = MainGrayTextColor;
        _goodsNumberLB.font = FontSet(14);
    }
    return _goodsNumberLB;
}

- (UIButton *)evaluationBtn{
    if (!_evaluationBtn) {
        _evaluationBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _evaluationBtn.frame = CGRectMake(self.goodsNumberLB.left - 55, self.goodsNumberLB.top-1, 52, 22);
        _evaluationBtn.clipsToBounds = YES;
        _evaluationBtn.layer.cornerRadius = 11;
        _evaluationBtn.layer.borderWidth = 1;
        _evaluationBtn.layer.borderColor = RGBA(255, 193, 77, 0.5f).CGColor;
        [_evaluationBtn setTitle:@"去评价" forState:normal];
        [_evaluationBtn setTitleColor:RGB(255, 188, 62) forState:normal];
        [_evaluationBtn.titleLabel setFont:FontSet(12)];
        [_evaluationBtn addTarget:self action:@selector(evaluationClick) forControlEvents:UIControlEventTouchUpInside];
    }
    return _evaluationBtn;
}
- (UIButton *)statusBtn{
    if (!_statusBtn) {
        _statusBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _statusBtn.frame = CGRectMake(self.evaluationBtn.left - 65, self.goodsNumberLB.top-1, 52, 22);
        [_statusBtn setTitleColor:RGB(255, 188, 62) forState:normal];
        [_statusBtn.titleLabel setFont:FontSet(12)];
    }
    return _evaluationBtn;
}

//去评价
-(void)evaluationClick{
}

//点击头像进入商品详情
-(void)tapClick:(UIGestureRecognizer *)ges{
    [self jumpGoodsDetailWithID:self.model.productId];
}
-(void)jumpGoodsDetailWithID:(NSInteger)goodsId{
    GoodsDetailsViewController *vc = [[GoodsDetailsViewController alloc] init];
    vc.goodsID = goodsId;
    [[Configuration getCurrentVC].navigationController pushViewController:vc animated:YES];
}



@end
